<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="上报时间" prop="reportingDate">
        <el-date-picker clearable
          v-model="queryParams.reportingDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择上报时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="原纸卷号" prop="rollNumber">
        <el-input
          v-model="queryParams.rollNumber"
          placeholder="请输入原纸卷号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备ID" prop="machineryId">
        <el-input
          v-model="queryParams.machineryId"
          placeholder="请输入设备ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编码" prop="machineryCode">
        <el-input
          v-model="queryParams.machineryCode"
          placeholder="请输入设备编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称" prop="machineryName">
        <el-input
          v-model="queryParams.machineryName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="带班" prop="lead">
        <el-input
          v-model="queryParams.lead"
          placeholder="请输入带班"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单ID" prop="workorderId">
        <el-input
          v-model="queryParams.workorderId"
          placeholder="请输入工单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作单号" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入工作单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单名称" prop="workorderName">
        <el-input
          v-model="queryParams.workorderName"
          placeholder="请输入工单名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品ID" prop="itemId">
        <el-input
          v-model="queryParams.itemId"
          placeholder="请输入产品ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截断长" prop="paperLong">
        <el-input
          v-model="queryParams.paperLong"
          placeholder="请输入截断长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预印米数" prop="preprintingMeters">
        <el-input
          v-model="queryParams.preprintingMeters"
          placeholder="请输入预印米数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预印张数" prop="preprintingNumber">
        <el-input
          v-model="queryParams.preprintingNumber"
          placeholder="请输入预印张数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="异常停机超时" prop="abnormalShutdownTimeout">
        <el-input
          v-model="queryParams.abnormalShutdownTimeout"
          placeholder="请输入异常停机超时"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报废重量/KG" prop="scrapWeight">
        <el-input
          v-model="queryParams.scrapWeight"
          placeholder="请输入报废重量/KG"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调机换单" prop="changeOrders">
        <el-input
          v-model="queryParams.changeOrders"
          placeholder="请输入调机换单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打样套数" prop="sampleNumber">
        <el-input
          v-model="queryParams.sampleNumber"
          placeholder="请输入打样套数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="助1" prop="assistant">
        <el-input
          v-model="queryParams.assistant"
          placeholder="请输入助1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="·" prop="info">
        <el-input
          v-model="queryParams.info"
          placeholder="请输入·"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="每米单重" prop="meterWeight">
        <el-input
          v-model="queryParams.meterWeight"
          placeholder="请输入每米单重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报废米数" prop="scrapMeters">
        <el-input
          v-model="queryParams.scrapMeters"
          placeholder="请输入报废米数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班次" prop="workGroup">
        <el-input
          v-model="queryParams.workGroup"
          placeholder="请输入班次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报表号" prop="reportNo">
        <el-input
          v-model="queryParams.reportNo"
          placeholder="请输入报表号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="理论产量" prop="theoreticalYield">
        <el-input
          v-model="queryParams.theoreticalYield"
          placeholder="请输入理论产量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报工状态(1=草稿,2=已报工)" prop="fbStatus">
        <el-select v-model="queryParams.fbStatus" placeholder="请选择报工状态(1=草稿,2=已报工)" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['fb:preprinting:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['fb:preprinting:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fb:preprinting:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="preprintingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录ID" align="center" prop="recordId" />
      <el-table-column label="上报时间" align="center" prop="reportingDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="原纸卷号" align="center" prop="rollNumber" />
      <el-table-column label="设备ID" align="center" prop="machineryId" />
      <el-table-column label="设备编码" align="center" prop="machineryCode" />
      <el-table-column label="设备名称" align="center" prop="machineryName" />
      <el-table-column label="带班" align="center" prop="lead" />
      <el-table-column label="工单ID" align="center" prop="workorderId" />
      <el-table-column label="工作单号" align="center" prop="workorderCode" />
      <el-table-column label="工单名称" align="center" prop="workorderName" />
      <el-table-column label="产品ID" align="center" prop="itemId" />
      <el-table-column label="产品编码" align="center" prop="itemCode" />
      <el-table-column label="产品名称" align="center" prop="itemName" />
      <el-table-column label="截断长" align="center" prop="paperLong" />
      <el-table-column label="预印米数" align="center" prop="preprintingMeters" />
      <el-table-column label="预印张数" align="center" prop="preprintingNumber" />
      <el-table-column label="异常停机超时" align="center" prop="abnormalShutdownTimeout" />
      <el-table-column label="报废重量/KG" align="center" prop="scrapWeight" />
      <el-table-column label="调机换单" align="center" prop="changeOrders" />
      <el-table-column label="打样套数" align="center" prop="sampleNumber" />
      <el-table-column label="生产情况" align="center" prop="proSituation" />
      <el-table-column label="助1" align="center" prop="assistant" />
      <el-table-column label="·" align="center" prop="info" />
      <el-table-column label="每米单重" align="center" prop="meterWeight" />
      <el-table-column label="报废米数" align="center" prop="scrapMeters" />
      <el-table-column label="班次" align="center" prop="workGroup" />
      <el-table-column label="报表号" align="center" prop="reportNo" />
      <el-table-column label="理论产量" align="center" prop="theoreticalYield" />
      <el-table-column label="报工状态(1=草稿,2=已报工)" align="center" prop="fbStatus" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注2" align="center" prop="remark2" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fb:preprinting:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fb:preprinting:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预印报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="上报时间" prop="reportingDate">
          <el-date-picker clearable
            v-model="form.reportingDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上报时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="原纸卷号" prop="rollNumber">
          <el-input v-model="form.rollNumber" placeholder="请输入原纸卷号" />
        </el-form-item>
        <el-form-item label="设备ID" prop="machineryId">
          <el-input v-model="form.machineryId" placeholder="请输入设备ID" />
        </el-form-item>
        <el-form-item label="设备编码" prop="machineryCode">
          <el-input v-model="form.machineryCode" placeholder="请输入设备编码" />
        </el-form-item>
        <el-form-item label="设备名称" prop="machineryName">
          <el-input v-model="form.machineryName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="带班" prop="lead">
          <el-input v-model="form.lead" placeholder="请输入带班" />
        </el-form-item>
        <el-form-item label="工单ID" prop="workorderId">
          <el-input v-model="form.workorderId" placeholder="请输入工单ID" />
        </el-form-item>
        <el-form-item label="工作单号" prop="workorderCode">
          <el-input v-model="form.workorderCode" placeholder="请输入工作单号" />
        </el-form-item>
        <el-form-item label="工单名称" prop="workorderName">
          <el-input v-model="form.workorderName" placeholder="请输入工单名称" />
        </el-form-item>
        <el-form-item label="产品ID" prop="itemId">
          <el-input v-model="form.itemId" placeholder="请输入产品ID" />
        </el-form-item>
        <el-form-item label="产品编码" prop="itemCode">
          <el-input v-model="form.itemCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="截断长" prop="paperLong">
          <el-input v-model="form.paperLong" placeholder="请输入截断长" />
        </el-form-item>
        <el-form-item label="预印米数" prop="preprintingMeters">
          <el-input v-model="form.preprintingMeters" placeholder="请输入预印米数" />
        </el-form-item>
        <el-form-item label="预印张数" prop="preprintingNumber">
          <el-input v-model="form.preprintingNumber" placeholder="请输入预印张数" />
        </el-form-item>
        <el-form-item label="异常停机超时" prop="abnormalShutdownTimeout">
          <el-input v-model="form.abnormalShutdownTimeout" placeholder="请输入异常停机超时" />
        </el-form-item>
        <el-form-item label="报废重量/KG" prop="scrapWeight">
          <el-input v-model="form.scrapWeight" placeholder="请输入报废重量/KG" />
        </el-form-item>
        <el-form-item label="调机换单" prop="changeOrders">
          <el-input v-model="form.changeOrders" placeholder="请输入调机换单" />
        </el-form-item>
        <el-form-item label="打样套数" prop="sampleNumber">
          <el-input v-model="form.sampleNumber" placeholder="请输入打样套数" />
        </el-form-item>
        <el-form-item label="生产情况">
          <editor v-model="form.proSituation" :min-height="192"/>
        </el-form-item>
        <el-form-item label="助1" prop="assistant">
          <el-input v-model="form.assistant" placeholder="请输入助1" />
        </el-form-item>
        <el-form-item label="·" prop="info">
          <el-input v-model="form.info" placeholder="请输入·" />
        </el-form-item>
        <el-form-item label="每米单重" prop="meterWeight">
          <el-input v-model="form.meterWeight" placeholder="请输入每米单重" />
        </el-form-item>
        <el-form-item label="报废米数" prop="scrapMeters">
          <el-input v-model="form.scrapMeters" placeholder="请输入报废米数" />
        </el-form-item>
        <el-form-item label="班次" prop="workGroup">
          <el-input v-model="form.workGroup" placeholder="请输入班次" />
        </el-form-item>
        <el-form-item label="报表号" prop="reportNo">
          <el-input v-model="form.reportNo" placeholder="请输入报表号" />
        </el-form-item>
        <el-form-item label="理论产量" prop="theoreticalYield">
          <el-input v-model="form.theoreticalYield" placeholder="请输入理论产量" />
        </el-form-item>
        <el-form-item label="报工状态(1=草稿,2=已报工)">
          <el-radio-group v-model="form.fbStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注">
          <editor v-model="form.remark" :min-height="192"/>
        </el-form-item>
        <el-form-item label="备注2">
          <editor v-model="form.remark2" :min-height="192"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPreprinting, getPreprinting, delPreprinting, addPreprinting, updatePreprinting } from "@/api/mes/fb/preprinting";

export default {
  name: "Preprinting",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预印报表格数据
      preprintingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportingDate: null,        rollNumber: null,        machineryId: null,        machineryCode: null,        machineryName: null,        lead: null,        workorderId: null,        workorderCode: null,        workorderName: null,        itemId: null,        itemCode: null,        itemName: null,        paperLong: null,        preprintingMeters: null,        preprintingNumber: null,        abnormalShutdownTimeout: null,        scrapWeight: null,        changeOrders: null,        sampleNumber: null,        proSituation: null,        assistant: null,        info: null,        meterWeight: null,        scrapMeters: null,        workGroup: null,        reportNo: null,        theoreticalYield: null,        fbStatus: null,        remark2: null,      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预印报列表 */
    getList() {
      this.loading = true;
      listPreprinting(this.queryParams).then(response => {
        this.preprintingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordId: null,        reportingDate: null,        rollNumber: null,        machineryId: null,        machineryCode: null,        machineryName: null,        lead: null,        workorderId: null,        workorderCode: null,        workorderName: null,        itemId: null,        itemCode: null,        itemName: null,        paperLong: null,        preprintingMeters: null,        preprintingNumber: null,        abnormalShutdownTimeout: null,        scrapWeight: null,        changeOrders: null,        sampleNumber: null,        proSituation: null,        assistant: null,        info: null,        meterWeight: null,        scrapMeters: null,        workGroup: null,        reportNo: null,        theoreticalYield: null,        fbStatus: 0,        remark: null,        remark2: null,        delFlag: null,        createBy: null,        createTime: null,        updateBy: null,        updateTime: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预印报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recordId = row.recordId || this.ids
      getPreprinting(recordId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预印报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recordId != null) {
            updatePreprinting(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPreprinting(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordIds = row.recordId || this.ids;
      this.$modal.confirm('是否确认删除预印报编号为"' + recordIds + '"的数据项？').then(function() {
        return delPreprinting(recordIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fb/preprinting/export', {
        ...this.queryParams
      }, `preprinting_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
